﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ZG_member
{
    class RPCClass
    {
        //CB代表CALLBACK数据
        [StructLayout(LayoutKind.Sequential, Size = 1166)]
        /// <summary>
        /// 消息结构体
        /// </summary>
        internal struct CB_RfidCardRequestAndReadData
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
            public byte[] CallBackData;
        }
        internal struct CB_CounterPrinteDemand
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public byte[] CallBackData;
        }
        internal struct CB_CounterCleaningDemand
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public byte[] CallBackData;
        }
        internal struct CB_SerialnumberPrinteDemand
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public byte[] CallBackData;
        }
        internal struct CB_RfidCardRequestAndReadNum
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public byte[] CallBackData;
        }

        internal struct CB_RefreshPrinterSetting
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public byte[] CallBackData;
        }
        internal struct CB_MagCardReadTrackIso
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 350)]
            public byte[] CallBackData;
        }
        internal struct CB_MagCardReadTrackIsoORJis
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 400)]
            public byte[] CallBackData;
        }
        internal struct CB_MagCardReadTrackJis
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 350)]
            public byte[] CallBackData;
        }

        //ref有进有出，ref只出不进
        internal class RCP11Class
        {
            //启动服务
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CommOpen(int port, int bandrate);//串口号 波特率
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CommClose(int m_hCom);
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CommRead(int m_hCom, ref byte[] buf);
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CommReadTimeShort(int m_hCom, ref byte[] buf);
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CommWrite(int m_hCom, byte[] buf, Int32 dwLength);
            //寻卡命令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardRequest(int m_hCom);
            //读取卡片序列号
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardReadNum(int m_hCom, ref byte[] code);
            //校验密码
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardPasswordVerify(int m_hCom, byte blocknum, byte keymodel, byte[] key);
            //读数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardReadData(int m_hCom, byte blocknum, ref byte[] code);
            //写数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardWriteData(int m_hCom, byte blocknum, ref byte[] data);


            //值初始化
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardInitialData(int m_hCom, byte blocknum, byte[] data);
            //增值操作
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardAddData(int m_hCom, byte blocknum, byte[] data);
            //减值操作
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardMinusData(int m_hCom, byte blocknum, byte[] data);
            //读EEPROM
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardReadEEPROM(int m_hCom, byte datanum, byte[] addr, ref byte[] code);
            //写EEPROM
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardWriteEEPROM(int m_hCom, byte datanum, byte[] addr, ref byte[] data);
            //调EEPROM的自定义的设置
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardSetEEPROM(int m_hCom, byte[] addr);
            //调EEPROM密钥
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardSetEEPROMKey(int m_hCom, byte blocknum, byte keymodel, ref byte[] addr);
            //恢复出厂设置
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardInitSetting(int m_hCom);


            //天线开关
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardAntennaOnOff(int m_hCom, byte OnOff);
            //寻卡并返回序列号
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardRequestAndReadNum(int m_hCom, out CB_RfidCardRequestAndReadNum CallBackData);
            //寻卡读卡
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardRequestAndReadData(int m_hCom, byte blocknum, byte keymodel, byte[] key, out CB_RfidCardRequestAndReadData CallBackData);
            //寻卡并写卡
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RfidCardRequestAndWriteData(int m_hCom, byte blocknum, byte keymodel, byte[] key, byte[] data);

            //磁卡清缓冲准备读卡
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardReadReady(int m_hCom);
            //读磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardReadTrackAll(int m_hCom, byte mode, ref byte[] code);
            //读ISO磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardReadTrackIso(int m_hCom, out CB_MagCardReadTrackIso CallBackData);
            //读ISO磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardReadTrackJis(int m_hCom, out CB_MagCardReadTrackJis CallBackData);
            //读两次磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardReadTrackIsoORJis(int m_hCom, out CB_MagCardReadTrackIsoORJis CallBackData);
            //写磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardWriteTrackAll(int m_hCom, byte mode, byte[] code);
            //自动写磁卡全轨数据
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int MagCardWriteTrack_AllAuto(int m_hCom, byte mode, byte[] code);


            //进卡指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCardIn(int m_hCom);
            //弹卡指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCardOut(int m_hCom);
            //单独擦卡指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCardSingleErase(int m_hCom);
            //机器清洗指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCleaningAuto(int m_hCom);
            //自动进卡指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCardInputAuto(int m_hCom);
            //机器清洗指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPCardOutputAuto(int m_hCom);
            //蜂鸣器响指令
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RCPBeepOpenTime(int m_hCom, byte ontime);
            //查询状态
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int StatusDemand(int m_hCom);
            //查询清洗计数
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CounterCleaningDemand(int m_hCom, out CB_CounterCleaningDemand CallBackData);
            //查询打印计数
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int CounterPrinteDemand(int m_hCom, out CB_CounterPrinteDemand CallBackData);

            //调出EEPROM配置值
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int RefreshPrinterSetting(int m_hCom, byte commandnum, out CB_RefreshPrinterSetting CallBackData);
            //配置EEPROM的设置
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int SetPrinterSetting(int m_hCom, byte commandnum, byte data);

            //查询打印机序列号
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int SerialnumberPrinteDemand(int m_hCom, out CB_SerialnumberPrinteDemand CallBackData);

            //配置打印机参数通用函数
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int PrinterSetting(int m_hCom, byte commandnum, byte bytenum, ref byte[] data);

            //打印函数
            [DllImport(@"RCPV11_VCDLL.dll")]
            public static extern int PrintStr(byte[] printer, byte[] strText, int x, int y, int direction, byte[] fontname, int fontsize);
        }
    }
}
